package action_行为型.interpreter_pattern_解释器模式;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/08/11:20
 * @Description:
 */
public class InterpreterPatternDemo {

	//规则zhangsan和lisi是男性
	public static Expression getMaleExpression() {
		TerMinalExpression zhangsan = new TerMinalExpression("张三");
		TerMinalExpression lisi = new TerMinalExpression("李四");
		return new OrExpression(zhangsan, lisi);
	}

	//规则：Julie 是一个已婚的女性
	public static Expression getMarriedWomanExpression() {
		TerMinalExpression zhangsan = new TerMinalExpression("Julie");
		TerMinalExpression lisi = new TerMinalExpression("Married");
		return new AndExpression(zhangsan, lisi);
	}

	public static void main(String[] args) {
		Expression maleExpression = getMaleExpression();
		Expression marriedWomanExpression = getMarriedWomanExpression();

		System.err.println(maleExpression.interpret("张三"));

		System.err.println(marriedWomanExpression.interpret("Julie"));
		System.err.println(marriedWomanExpression.interpret("Married Julie"));
	}
}
